﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 泛型
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Persons ps = new Persons(); 
            Person p = new Person() { Age = 4,Name = "yejing"};
            ps.Add(p);

            foreach (var item in ps)
            {
                Console.WriteLine((item as Person).Name);
            }

            Console.ReadKey();
        }
    }


    public class Person
    {
        protected int age;
        public int Age { get { return age; } set { age = value; } }
        protected string name;
        public string Name { get { return name; } set { name = value;} }

        public Person()
        {

        }
    }

    public class Persons:IEnumerable<Person>
    {
        private List<Person> list = new List<Person>();

        public IEnumerator<Person> GetEnumerator() => list.GetEnumerator();
        IEnumerator IEnumerable.GetEnumerator() => list.GetEnumerator();

        public void Add(Person p)
        {
            list.Add(p);
        }

        public int Count() => list.Count;


    }
   
}
